@extends('layouts/app')

@section('content')
    <div class="order-detail">
            <form action="" name="info" id="info">
                @csrf
                <div class="order-info takeout">
                    {{--<div class="order-panel">--}}
                        {{--<div class="order-header">--}}
                            {{--<h3 class="shop-name arrow-right">--}}
                                {{--<svg class="icon f48" aria-hidden="true">--}}
                                    {{--<use xlink:href="#icon-weibiaoti--3"></use>--}}
                                {{--</svg>--}}
                                {{--<span class="f30" id="shopsName">我是标题</span>--}}
                            {{--</h3>--}}
                        {{--</div>--}}
                        {{--<div class="order-header">--}}
                            {{--<h3 class="shop-name">--}}
                                {{--<span class="f30">订单号：<span id="orderNumber">123456</span></span>--}}
                            {{--</h3>--}}
                        {{--</div>--}}
                        {{--<div class="order-header">--}}
                            {{--<h3 class="shop-name">--}}
                                {{--<span class="f30">类型：<span id="orderType">外卖</span></span>--}}
                            {{--</h3>--}}
                        {{--</div>--}}

                        {{--<div class="order-content">--}}
                            {{--<div class="foods">--}}
                                {{--<p class="f16 gary9">我是那个菜名x1 <span class="f14 gary9 pull-right">￥20</span></p>--}}
                                {{--<p class="f16 gary9">我是那个菜名x1 <span class="f14 gary9 pull-right">￥20</span></p>--}}
                                {{--<p class="f16 gary9">我是那个菜名x1 <span class="f14 gary9 pull-right">￥20</span></p>--}}
                            {{--</div>--}}
                            {{--<div class="foods-info">--}}
                                {{--<p class="f18 gary9">配送费 <span class="f14 gary9 pull-right fee">￥20</span></p>--}}
                                {{--<p class="f18 gary9">优惠金额 <span class="f14 gary9 pull-right">￥ <span class="prePrice">20</span></span></p>--}}
                                {{--<p class="f18 gary9">总计 <span class="f14 gary9 pull-right">￥<span class="total">20</span></span></p>--}}
                            {{--</div>--}}
                        {{--</div>--}}
                    {{--</div>--}}
                    {{--<div class="order-panel">--}}
                        {{--<div class="order-header">--}}
                            {{--<p class="f20">备注: <span id="content"></span></p>--}}
                            {{--<p class="f20 mt-10">下单时间: <span id="time">2018-07-09</span></p>--}}
                            {{--<p class="f20 mt-10" id="payWay">支付方式: <span>2018-07-09</span></p>--}}
                        {{--</div>--}}
                    {{--</div>--}}
                    {{--<div class="btn-group">--}}
                        {{--<div class="weui-cell no-border">--}}
                            {{--<button type="button" class="weui-btn weui-btn_primary f30">再来一单</button>--}}
                        {{--</div>--}}
                        {{--<div class="weui-cell no-border">--}}
                            {{--<button type="button" class="weui-btn weui-btn_white f30">评价</button>--}}
                        {{--</div>--}}
                    {{--</div>--}}

                    {{--<div class="btn-round">--}}
                        {{--<div class="round">--}}
                            {{--<svg class="icon white" aria-hidden="true">--}}
                                {{--<use xlink:href="#icon-weibiaoti--26"></use>--}}
                            {{--</svg>--}}
                        {{--</div>--}}
                        {{--<div class="small-round small-round1">--}}
                            {{--<a href="" class="f24 white">加菜</a>--}}
                        {{--</div>--}}
                        {{--<div class="small-round small-round2 f24 white">服务</div>--}}
                    {{--</div>--}}
                </div>
            </form>

        <div id="editType" class="weui-popup__container popup-bottom">
            <input class="weui-input" id="order_id" name="order_id" type="hidden">
            <div class="weui-popup__overlay"></div>
            <div class="weui-popup__modal">
                <div class="toolbar">
                    <div class="toolbar-inner">
                        <a href="javascript:;" class="picker-button close-popup">关闭</a>
                        <h1 class="title">邀请函信息</h1>
                    </div>
                </div>
                <div class="modal-content">
                    <div class="weui-cells weui-cells_form">
                        <div class="weui-cell">
                            <div class="weui-cell__hd"><label class="weui-label">邀请标题</label></div>
                            <div class="weui-cell__bd">
                                <input class="weui-input" id="title" name="title" type="text"  placeholder="邀请主题">
                            </div>
                        </div>
                        <div class="weui-cell">
                            <div class="weui-cell__bd">
                                <textarea class="weui-textarea" name="content" id="content" placeholder="请输入内容" rows="3"></textarea>
                            </div>
                        </div>
                        <div class="weui-cell weui-cell_select">
                            <div class="weui-cell__bd">
                                <select class="weui-select" id="templet" name="templet">
                                    <option selected="" value="1">普通模板</option>
                                    <option value="2">生日模板</option>
                                    <option value="3">喜酒模板</option>
                                </select>
                            </div>
                        </div>
                        <div class="weui-cell">
                            <button class="weui-btn weui-btn_primary f30" onclick="addInvitation()">生成邀请函</button>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <script>
        var id = getRequest().id,
            order_type = getRequest().order_type;
            _token = $("input[name='_token']").val();
        console.log("id", id);

        getOrderDetail(id, order_type);

        // 获取订单数据
        function getOrderDetail(id, order_type) {
            $.post("/api/user/orderDetail", {_token: _token, id: id, order_type: order_type}, function (res) {

                if (typeof res === 'string') {
                    res = JSON.parse(res);
                }
                // 根据订单类型选择渲染的模板
                console.log("res", res);
                var data = {};
                data['type'] = 'orderDetail';
                data['element'] = '.order-info';
                data['data'] = res.data;

                // 渲染数据
                A.init(data);
            });
        }



        // 我已经到店
        $(".order-detail").on('click', '#in-here', function () {
            console.log("我已经到店");//api/arrivaledShop
            var id = $(this).attr('data-id');

            $.post("/api/arrivaledShop", {id: id}, function (res) {
                if (typeof res === 'string') {
                    res = JSON.parse(res);
                }
                $.alert(res.info, function () {
                    if (res.code == 200) {
                        location.reload();
                    }
                });
            });
        });

        //申请退款
        $(".order-detail").on('click', '#refund', function () {
            console.log("我要退钱");
            var id = $(this).attr('data-id');

            $.post("/api/applyForRefund", {id: id}, function (res) {
                if (typeof res === 'string') {
                    res = JSON.parse(res);
                }
                $.alert(res.info, function () {
                    if (res.code == 200) {
                        location.reload();
                    }
                });
            });
        });

        // 点击呼叫服务
        $(".order-detail").on('click', '.btn-round', function () {

            var has = $(".small-round").hasClass("active");

            if (has) {
                $(".small-round").removeClass("active");
            } else {
                $(".small-round").addClass("active");
            }


        });
        // 呼叫服务
        $(".order-detail").on('click', '.service', function () {
            //api/callAttendant

            var id = $(this).attr('data-id');

            $.post("/api/callAttendant", {id: id}, function (res) {
                if (typeof res === 'string') {
                    res = JSON.parse(res);
                }
                $.alert(res.info);
            });
        });
        // 去结账pay-money

        $(".order-detail").on('click', '.pay-money', function () {
            //api/callAttendant

            var id = $(this).attr('data-id');

            $.post("/api/callAttendant", {id: id}, function (res) {
                if (typeof res === 'string') {
                    res = JSON.parse(res);
                }
                $.alert(res.info);
            });
        });

        // 取消定单
        $(".order-detail").on('click', '.canel-order', function () {
            $.toast("暂时不支持取消定单", "text");
        });

        // 打开生成邀请函信息填写面板
        $(".order-detail").on('click', '.invitation', function () {
            $.post("/api/showinvitation", {order_id: id }, function (res) {
                if (typeof res === 'string') {
                    res = JSON.parse(res);
                }

                console.log("res", res);

                if (res.code != 200) {
                    $(".btn-round").hide();
                    $("#editType").popup();
                } else {
                    location.href = "/mobile/invitation?id=" + res.data.id;
                }

            });

        });
        //确认收货
        $(".order-detail").on('click','.receipt',function(){
            $.post("/api/confirmReceipt",{id:id},function(res){
                if(typeof res === 'string'){
                    res = JSON.parse(res);
                }
                console.log("res",res);
                //刷新
                location.reload();
            })

        });

        // 生成邀请函
        function addInvitation () {
            var data = {};
            data['order_id'] = id;
            data['title'] = $("#title").val();
            data['content'] = $("#content").val();
            data['templet'] = $("#templet").val();
            console.log("data", data);
            if (!data['title']) {
                return $.toast("标题不能为空", "text");
            } else if (!data['content']) {
                return $.toast("内容不能为空", "text");
            }

            $.post("/api/buildinvitation", data, function (res) {
                if (typeof res === "string") {
                    res = JSON.parse(res);
                }

                $.alert(res.info, function () {
                    $.closePopup();
                    $(".btn-round").show();
                });
            });

        }
    </script>
@endsection


@extends('layouts/footer')
